<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="结点名称" prop="nodeName">
        <el-input
          v-model="queryParams.nodeName"
          placeholder="请输入结点名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程状态" prop="flowStatus">
        <el-select v-model="queryParams.flowStatus" placeholder="请选择流程状态" clearable>
          <el-option
            v-for="dict in dict.type.node_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="流程版本" prop="flowVersion">
        <el-input
          v-model="queryParams.flowVersion"
          placeholder="请输入流程版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程创建者" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入流程创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          clearable size="small"
          v-model="queryParams.createTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="instanceList"
              :row-style="{ height:'0px' }"
              :cell-style="{ padding:'0px' }"
              :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
              @sort-change="handleSortChange"
              stripe border max-height="560" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column label="流程名称" align="center" prop="flowName" sortable="custom" :show-overflow-tooltip="true"/>
      <el-table-column label="任务名称" align="center" prop="nodeName" sortable="custom" :show-overflow-tooltip="true"/>
      <el-table-column label="流程发起人" align="center" prop="userName" sortable="custom" :show-overflow-tooltip="true"/>
      <el-table-column label="结点类型" align="center" prop="flowStatus" sortable="custom" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.node_type" :value="scope.row.flowStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="流程版本" align="center" prop="flowVersion" sortable="custom" :show-overflow-tooltip="true"/>
      <el-table-column label="创建者" align="center" prop="createBy" sortable="custom" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160" sortable="custom" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="110" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handle(scope.row.id)"
            v-hasPermi="['flow:instance:hand']"
          >办理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <Dialog ref="dialog" @refresh="getList"></Dialog>
  </div>
</template>

<script>
import { listInstance } from "@/api/flow/instance";
import Dialog from "@/views/flow/task/dialog";


export default {
  name: "Todo",
  dicts: ['node_type'],
  components: {
    Dialog
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 流程实例表格数据
      instanceList: [],
      todoDetail: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nodeName: null,
        flowStatus: null,
        flowVersion: null,
        userName: null,
        createBy: null,
        createTime: null,
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询流程实例列表 */
    getList() {
      this.loading = true;
      listInstance(this.queryParams).then(response => {
        this.instanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 办理按钮操作 */
    handle(id) {
      this.$refs.dialog.show(id);
      // // 实际情况是，不同条件对应不同的页面，所以用动态组件
      // let path = 'flow/task/dialog' ;
      // this.todoDetail = (resolve) => require([`@/views/${path}`], resolve)
      // console.log(this.$refs.detail, 'this.$refs.detail')
      // // return this.todoDetail
      // // this.$refs.detail.show(id, true);
    },
    handleSortChange(column) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
  }
};
</script>
